
--migração do título pagos
insert into BancoGerencial..ContaPagar(
DataMovimento,
DataVencimento,
CodFornecedor,
Valor, 
Parcela,
TotalParcela,
Observacao,
DataPagamento,
ValorPago,
DataHoraUltimaGravacao,
UsuarioUltimaGravacao
)
select 
rec.DTLANC,
rec.DTVENC,
rec.CODCLI,
rec.VALORTOT,
'1',
'1',
'NF:' + NOTAFISCAL + '' + SUBSTRING(OBS, 1,160),
rec.DTPAG,
rec.VALORTOT,
GETDATE(),
'MIGRAÇÃO'
from SaoJose2020..Pagar as rec
where rec.DTPAG is not null
and rec.CODCLI > 0
and rec.CANCELADA is null
and rec.CODCLI IN (SELECT CODIGO FROM Fornecedor)

select * from SaoJose2020..Pagar

update ContaPagar set CodEmp = 1

update BancoGerencial..ContaPagar
set NomeFornecedor = OutraTabela.Nome
from (select Nome, Codigo from BancoGerencial..Fornecedor) as OutraTabela
where OutraTabela.Codigo = ContaPagar.CodFornecedor